<?php
namespace app\common\model;

use think\Db;
use think\Model;

class Ad extends Model
{

    protected static function init()
    {
        parent::init();

        self::event('before_insert', function ($ad) {
            $start_time = $ad->start_time;
            $end_time = $ad->end_time;
            if ($start_time) {
                $ad->start_time = strtotime($start_time);
            }
            if ($end_time) {
                $ad->end_time = strtotime($end_time);
            }
        });
        
        self::event('before_update', function ($ad) {
            $start_time = $ad->start_time;
            $end_time = $ad->end_time;
            if ($start_time) {
                $ad->start_time = strtotime($start_time);
            }
            if ($end_time) {
                $ad->end_time = strtotime($end_time);
            }
        });
    }
}